home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / ghostscr / gsview07.zip / dialog.c < prev    next >
C/C++ Source or Header  |  1993-04-30  |  19KB  |  632 lines

  1. /*
  2.  * dialog.c -- General dialog boxes for GSVIEW.EXE, 
  3.  *              a graphical interface for MS-Windows Ghostscript
  4.  * Copyright (C) 1993  Russell Lang
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  *   Author: Russell Lang
  21.  * Internet: rjl@monu1.cc.monash.edu.au
  22.  */
  23.  
  24. #define STRICT
  25. #include <windows.h>
  26. #include <windowsx.h>
  27. #include <commdlg.h>
  28. #include <shellapi.h>
  29. #include <mmsystem.h>
  30. #include <stdio.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. #include <dir.h>
  35. #define NeedFunctionPrototypes 1
  36. #include "ps.h"
  37. #include "gsview.h"
  38.  
  39.  
  40. BOOL
  41. getfilename(LPSTR filename, BOOL save, UINT filter, UINT title, UINT help)
  42. {
  43. LPSTR old_lpstrFile;
  44. LPCSTR old_lpstrTitle;
  45. char szTitle[MAXSTR];
  46. BOOL flag;
  47.     if (help)
  48.         LoadString(phInstance, help, szHelpTopic, sizeof(szHelpTopic));
  49.     old_lpstrTitle = ofn.lpstrTitle;
  50.     if (title) {
  51.         LoadString(phInstance, title, szTitle, sizeof(szTitle));
  52.         ofn.lpstrTitle = (LPCSTR)szTitle;
  53.     }
  54.     old_lpstrFile = ofn.lpstrFile;
  55.     if (filename != (LPSTR)NULL)
  56.         ofn.lpstrFile = filename;
  57.     ofn.nFilterIndex = filter;
  58.     if (save)
  59.         flag = GetSaveFileName(&ofn);
  60.     else
  61.         flag = GetOpenFileName(&ofn);
  62.     ofn.lpstrTitle = old_lpstrTitle;
  63.     ofn.lpstrFile = old_lpstrFile;
  64.     ofn.nFilterIndex = FILTER_PS;
  65.     return flag;
  66. }
  67.  
  68. /* Input Dialog Box structures */
  69. LPSTR input_prop = "input_prop";
  70. struct input_param {
  71.     LPSTR prompt;
  72.     LPSTR answer;
  73. };
  74.  
  75. BOOL
  76. get_string(char *prompt, char *answer)
  77. {
  78. struct input_param param;
  79. DLGPROC lpProcInput;
  80. BOOL flag;
  81.     param.answer = answer;
  82.     param.prompt = prompt;
  83.     lpProcInput = (DLGPROC)MakeProcInstance((FARPROC)InputDlgProc, phInstance);
  84.     flag = DialogBoxParam( phInstance, "InputDlgBox", hwndimg, lpProcInput, (LPARAM)¶m);
  85.     FreeProcInstance((FARPROC)lpProcInput);
  86.     return flag;
  87. }
  88.  
  89.  
  90. /* input string dialog box */
  91. BOOL CALLBACK _export
  92. InputDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  93. {
  94.     switch(message) {
  95.         case WM_INITDIALOG:
  96.         {
  97.           HLOCAL hlocal;
  98.           LPSTR *panswer;
  99.           struct input_param *pparam = (struct input_param *)lParam;
  100.           SetDlgItemText(hDlg, ID_PROMPT, pparam->prompt);
  101.           SetDlgItemText(hDlg, ID_ANSWER, pparam->answer);
  102.           /* save address of answer string in property list */
  103.           hlocal = LocalAlloc(LHND, sizeof(pparam->answer));
  104.           panswer = (LPSTR *)LocalLock(hlocal);
  105.           if (panswer != (LPSTR *)NULL) {
  106.             *panswer = pparam->answer;
  107.         LocalUnlock(hlocal);
  108.             SetProp(hDlg, input_prop, (HANDLE)hlocal);
  109.           }
  110.         }
  111.             return( TRUE);
  112.         case WM_COMMAND:
  113.             switch(LOWORD(wParam)) {
  114.         case ID_HELP:
  115.             SendMessage(hwndimg, help_message, 0, 0L);
  116.             return(FALSE);
  117.                 case ID_ANSWER:
  118.                     return(TRUE);
  119.         case IDOK:
  120.             {
  121.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  122.               LPSTR *panswer;
  123.                   panswer = (LPSTR *)LocalLock(hlocal);
  124.                   if (panswer != (LPSTR *)NULL) {
  125.                 GetDlgItemText(hDlg, ID_ANSWER, *panswer, MAXSTR);
  126.             LocalUnlock(hlocal);
  127.               }
  128.               LocalFree(hlocal);
  129.               RemoveProp(hDlg, input_prop);
  130.             }
  131.                     EndDialog(hDlg, TRUE);
  132.                     return(TRUE);
  133.                 case IDCANCEL:
  134.             {
  135.               HLOCAL hlocal = (HLOCAL)GetProp(hDlg, input_prop); 
  136.               LocalFree(hlocal);
  137.               RemoveProp(hDlg, input_prop);
  138.             }
  139.                     EndDialog(hDlg, FALSE);
  140.                     return(TRUE);
  141.                 default:
  142.                     return(FALSE);
  143.             }
  144.         default:
  145.             return(FALSE);
  146.     }
  147. }
  148.  
  149.  
  150. /* copyright dialog box */
  151. BOOL CALLBACK _export
  152. AboutDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  153. {
  154.     switch(message) {
  155.         case WM_INITDIALOG:
  156.             SetDlgItemText(hDlg, ABOUT_VERSION, GSVIEW_VERSION);
  157.             return( TRUE);
  158.     case WM_LBUTTONDBLCLK:
  159.         {DWORD dwUnit = GetDialogBaseUnits();
  160.         RECT rect; POINT pt;
  161.         pt.x = LOWORD(lParam); pt.y = HIWORD(lParam);
  162.         rect.left   =   8 * LOWORD(dwUnit) / 4;
  163.         rect.top    = 138 * HIWORD(dwUnit) / 8;
  164.         rect.right  = 240 * LOWORD(dwUnit) / 4 + rect.left;
  165.         rect.bottom =   8 * HIWORD(dwUnit) / 8 + rect.top;
  166.         if (PtInRect(&rect,pt)) {
  167.         BITMAP bm;
  168.         HBITMAP hbitmap_old;
  169.         HBITMAP hbitmap = LoadBitmap(phInstance,"gsview_bitmap");
  170.         HDC hdc = GetDC(hDlg);
  171.         HDC hdcsrc = CreateCompatibleDC(hdc);
  172.         hbitmap_old = SelectObject(hdcsrc,hbitmap);
  173.         GetObject(hbitmap, sizeof(BITMAP),&bm);
  174.         BitBlt(hdc, rect.right-bm.bmWidth,rect.bottom-bm.bmHeight,
  175.            bm.bmWidth,bm.bmHeight,hdcsrc,0,0,SRCCOPY);
  176.         SelectObject(hdcsrc,hbitmap_old);
  177.         DeleteObject(hbitmap);
  178.         DeleteDC(hdcsrc);
  179.         ReleaseDC(hDlg,hdc);
  180.         }
  181.         }
  182.         return FALSE;
  183.         case WM_COMMAND:
  184.             switch(LOWORD(wParam)) {
  185.                 case IDOK:
  186.                     EndDialog(hDlg, TRUE);
  187.                     return(TRUE);
  188.                 default:
  189.                     return(FALSE);
  190.             }
  191.         default:
  192.             return(FALSE);
  193.     }
  194. }
  195.  
  196. /* information about document dialog box */
  197. BOOL CALLBACK _export
  198. InfoDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  199. {
  200.     switch(message) {
  201.         case WM_INITDIALOG:
  202.       { char buf[MAXSTR];
  203.         int n;
  204.         if (dfname[0] != '\0') {
  205.                 SetDlgItemText(hDlg, INFO_FILE, dfname);
  206.         if (doc) {
  207.             if (is_ctrld)
  208.             LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
  209.             else  {
  210.             if (doc->epsf) {
  211.                 switch (preview) {
  212.                 case IDS_EPSI:
  213.                   LoadString(phInstance, IDS_EPSI, buf, sizeof(buf));
  214.                   break;
  215.                 case IDS_EPST:
  216.                   LoadString(phInstance, IDS_EPST, buf, sizeof(buf));
  217.                   break;
  218.                 case IDS_EPSW:
  219.                   LoadString(phInstance, IDS_EPSW, buf, sizeof(buf));
  220.                   break;
  221.                 default:
  222.                   LoadString(phInstance, IDS_EPSF, buf, sizeof(buf));
  223.                 }
  224.             }
  225.             else
  226.                 LoadString(phInstance, IDS_DSC, buf, sizeof(buf));
  227.             }
  228.                     SetDlgItemText(hDlg, INFO_TYPE, buf);
  229.             SetDlgItemText(hDlg, INFO_TITLE, doc->title ? doc->title : "");
  230.             SetDlgItemText(hDlg, INFO_DATE, doc->date ? doc->date : "");
  231.             sprintf(buf, "%d %d %d %d", doc->boundingbox[LLX], doc->boundingbox[LLY], 
  232.             doc->boundingbox[URX], doc->boundingbox[URY]);
  233.             SetDlgItemText(hDlg, INFO_BBOX, buf);
  234.             switch(doc->orientation) {
  235.             case LANDSCAPE:
  236.                     LoadString(phInstance, IDS_LANDSCAPE, buf, sizeof(buf));
  237.                 break;
  238.             case PORTRAIT:
  239.                     LoadString(phInstance, IDS_PORTRAIT, buf, sizeof(buf));
  240.                 break;
  241.             default:
  242.                 buf[0] = '\0';
  243.             }
  244.             SetDlgItemText(hDlg, INFO_ORIENT, buf);
  245.             switch(doc->pageorder) {
  246.             case ASCEND: 
  247.                     LoadString(phInstance, IDS_ASCEND, buf, sizeof(buf));
  248.                 break;
  249.             case DESCEND: 
  250.                     LoadString(phInstance, IDS_DESCEND, buf, sizeof(buf));
  251.                 break;
  252.             case SPECIAL:
  253.                     LoadString(phInstance, IDS_SPECIAL, buf, sizeof(buf));
  254.                 break;
  255.             default:
  256.                 buf[0] = '\0';
  257.             }
  258.             SetDlgItemText(hDlg, INFO_ORDER, buf);
  259.             if (doc->default_page_media && doc->default_page_media->name) {
  260.                 sprintf(buf,"%s %d %d",doc->default_page_media->name,
  261.                     doc->default_page_media->width,
  262.                     doc->default_page_media->height);
  263.             }
  264.             else {
  265.             buf[0] = '\0';
  266.             }
  267.             SetDlgItemText(hDlg, INFO_DEFMEDIA, buf);
  268.             sprintf(buf, "%d", doc->numpages);
  269.             SetDlgItemText(hDlg, INFO_NUMPAGES, buf);
  270.             n = map_page(pagenum - 1);
  271.             if (doc->pages)
  272.                 sprintf(buf, "\"%s\"   %d", doc->pages[n].label ? doc->pages[n].label : "", pagenum);
  273.             else
  274.                 buf[0] = '\0';
  275.             SetDlgItemText(hDlg, INFO_PAGE, buf);
  276.         
  277.         }
  278.         else {
  279.             LoadString(phInstance, IDS_NOTDSC, buf, sizeof(buf));
  280.                     SetDlgItemText(hDlg, INFO_TYPE, buf);
  281.         }
  282.         sprintf(buf, "%d \327 %d", bitmap_width, bitmap_height);
  283.         SetDlgItemText(hDlg, INFO_BITMAP, buf);
  284.         }
  285.         else {
  286.             LoadString(phInstance, IDS_NOFILE, buf, sizeof(buf));
  287.                 SetDlgItemText(hDlg, INFO_FILE, buf);
  288.        }
  289.       }
  290.           return( TRUE);
  291.     case WM_COMMAND:
  292.             switch(LOWORD(wParam)) {
  293.                 case IDOK:
  294.                     EndDialog(hDlg, TRUE);
  295.                     return(TRUE);
  296.                 case IDCANCEL:
  297.                     EndDialog(hDlg, FALSE);
  298.                     return(TRUE);
  299.                 default:
  300.                     return(FALSE);
  301.             }
  302.         default:
  303.             return(FALSE);
  304.     }
  305. }
  306.  
  307.  
  308. #define MAX_SYSTEM_SOUND 16
  309. char *system_sounds;
  310. char *sound_entry[MAX_SYSTEM_SOUND];
  311. char szNone[32];
  312. char szSpeaker[32];
  313. int system_num;
  314.  
  315. int
  316. load_sounds(void)
  317. {
  318.     char *p;
  319.     int j;
  320.  
  321.     /* add our two sounds */
  322.     sound_entry[0] = "";
  323.     sound_entry[1] = BEEP;
  324.     LoadString(phInstance, IDS_NONE, szNone, sizeof(szNone));
  325.     LoadString(phInstance, IDS_SPKR, szSpeaker, sizeof(szSpeaker));
  326.     /* get list of system sounds */
  327.     system_sounds = malloc(PROFILE_SIZE);
  328.     if (system_sounds != (char *)NULL) {
  329.         GetProfileString("sounds", NULL, "", system_sounds, PROFILE_SIZE);
  330.     }
  331.     p = system_sounds;
  332.     for (j=2; p!=(char *)NULL && j<MAX_SYSTEM_SOUND && strlen(p)!=0; j++) {
  333.         sound_entry[j] = p;    
  334.         p += strlen(p) + 1;
  335.     }
  336.     system_num = j;
  337.     return system_num;
  338. }
  339.  
  340. char *
  341. get_sound_entry(int index)
  342. {
  343.     return (sound_entry[index]);
  344. }
  345.  
  346. char *
  347. get_sound_name(int index)
  348. {
  349. static char buf[64];
  350. char *p;
  351.     if (index==0)
  352.         return szNone;
  353.     if (index==1)
  354.         return szSpeaker;
  355.         GetProfileString("sounds", sound_entry[index], ",", buf, sizeof(buf));
  356.         p = strchr(buf,',');
  357.         if (p != (char *)NULL)
  358.         return p+1;
  359.     return (char *)NULL;
  360. }
  361.  
  362. int 
  363. find_sound_name(char *entry)
  364. {
  365. int i;
  366.     for (i=0; i<system_num; i++) {
  367.         if (strcmp(entry, sound_entry[i])==0)
  368.             return i;
  369.     }
  370.     return -1;    /* no find */
  371. }
  372.  
  373. void
  374. add_sounds(HWND hDlg)
  375. {
  376. int ifile;
  377.     for (ifile=system_num-1; ifile>=0; ifile--)
  378.         SendDlgItemMessage(hDlg, SOUND_FILE, LB_INSERTSTRING, 0,
  379.              (LPARAM)(LPSTR)get_sound_name(ifile));
  380. }
  381.  
  382. void
  383. free_sounds(void)
  384. {
  385.     if (system_sounds != (char *)NULL)
  386.         free(system_sounds);
  387. }
  388.  
  389. BOOL CALLBACK _export
  390. SoundDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  391. {
  392.     char buf[MAXSTR];
  393.     int ievent, ifile;
  394.     static struct sound_s dsound[NUMSOUND];    /* copy of sound[] */
  395.     WORD notify_message;
  396.     char *szWaveFilter = "*.wav";
  397.     static char szPath[MAXSTR];
  398.     static int file_start;
  399.     char *p;
  400.  
  401.     switch (wmsg) {
  402.         case WM_INITDIALOG:
  403.         file_start = load_sounds();
  404.         for (ievent=0; ievent<NUMSOUND; ievent++) {
  405.             strcpy(dsound[ievent].file, sound[ievent].file);
  406.             LoadString(phInstance, sound[ievent].title, buf, sizeof(buf));
  407.             SendDlgItemMessage(hDlg, SOUND_EVENT, LB_ADDSTRING, 0, 
  408.             (LPARAM)((LPSTR)buf));
  409.         }
  410.         ievent = 0;
  411.         SendDlgItemMessage(hDlg, SOUND_EVENT, LB_SETCURSEL, ievent, 0L);
  412.         /* force update of SOUND_FILE */
  413.         SendDlgNotification(hDlg, SOUND_EVENT, LBN_SELCHANGE);
  414.         return TRUE;
  415.         case WM_COMMAND:
  416.         notify_message = GetNotification(wParam,lParam);
  417.         switch (LOWORD(wParam)) {
  418.             case ID_HELP:
  419.                 SendMessage(hwndimg, help_message, 0, 0L);
  420.                 return(FALSE);
  421.             case SOUND_EVENT:
  422.             if (notify_message != LBN_SELCHANGE) {
  423.                 return FALSE;
  424.             }
  425.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  426.             if (ievent == LB_ERR) {
  427.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  428.                 return FALSE;
  429.             }
  430.             ifile = find_sound_name(dsound[ievent].file);
  431.             if (ifile >= 0) {
  432.                 strcpy(buf, get_sound_name(ifile));
  433.                 szPath[0] = '\0';
  434.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  435.             }
  436.             else {
  437.                 /* must be WAVE file */
  438.                 strcpy(szPath, dsound[ievent].file);
  439.                 p = strrchr(szPath, '\\');
  440.                 if (p != (char *)NULL) {
  441.                     strcpy(buf,++p);
  442.                     *p = '\0';
  443.                 }
  444.                 else {
  445.                     strcpy(buf, szPath);
  446.                 }
  447.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  448.             }
  449.             strcat(szPath, szWaveFilter);
  450.             DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  451.             add_sounds(hDlg);
  452.             SendDlgItemMessage(hDlg, SOUND_FILE, LB_SELECTSTRING, file_start, (LPARAM)(LPSTR)buf);
  453.             return FALSE;
  454.             case SOUND_FILE:
  455.             if (notify_message == LBN_SELCHANGE) {
  456.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  457.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  458.                 ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  459.                 if (ifile >= file_start) {
  460.                 if (buf[0] == '[') { /* selected a directory */
  461.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), FALSE);
  462.                     }
  463.                 else { /* selected a WAVE file */
  464.                             int i = GetDlgItemText(hDlg, SOUND_PATH, dsound[ievent].file, MAXSTR);
  465.                         if (dsound[ievent].file[i-1] != '\\')
  466.                             dsound[ievent].file[i++] = '\\';
  467.                             DlgDirSelect(hDlg, dsound[ievent].file + i, SOUND_FILE);
  468.                     EnableWindow(GetDlgItem(hDlg, SOUND_TEST), TRUE);
  469.                 }
  470.                 }
  471.                 else {
  472.                 EnableWindow(GetDlgItem(hDlg, SOUND_TEST), ifile!=0);
  473.                 strcpy(dsound[ievent].file,get_sound_entry(ifile));
  474.                 }
  475.             }
  476.             if (notify_message == LBN_DBLCLK) {
  477.                 ifile = (int)SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETCURSEL, 0, 0L);
  478.                 SendDlgItemMessage(hDlg, SOUND_FILE, LB_GETTEXT, ifile, (LPARAM)(LPSTR)buf);
  479.                 if (buf[0] == '[') {
  480.                         DlgDirSelect(hDlg, szPath, SOUND_FILE);
  481.                     lstrcat(szPath, szWaveFilter);
  482.                         DlgDirList(hDlg, szPath, SOUND_FILE, SOUND_PATH, DDL_DRIVES | DDL_DIRECTORY);
  483.                 add_sounds(hDlg);
  484.                 }
  485.                 else {
  486.                 SendDlgNotification(hDlg, SOUND_TEST, BN_CLICKED);
  487.                 }
  488.             }
  489.             return FALSE;
  490.             case SOUND_TEST:
  491.             ievent = (int)SendDlgItemMessage(hDlg, SOUND_EVENT, LB_GETCURSEL, 0, 0L);
  492.             if (strlen(dsound[ievent].file)==0)
  493.                 return FALSE;
  494.             if (!is_win31 || (strcmp(dsound[ievent].file,BEEP)==0)) {
  495.                 MessageBeep(-1);
  496.                 return FALSE;
  497.             }
  498.             if (is_win31) {
  499.                 if (lpfnSndPlaySound != (FPSPS)NULL) 
  500.                         lpfnSndPlaySound(dsound[ievent].file, SND_SYNC);
  501.                 else
  502.                     MessageBeep(-1);
  503.                 return FALSE;
  504.             }
  505.             return FALSE;
  506.             case IDOK:
  507.             for (ievent=0; ievent<NUMSOUND; ievent++)
  508.                 strcpy(sound[ievent].file, dsound[ievent].file);
  509.             free_sounds();
  510.             EndDialog(hDlg, TRUE);
  511.             return TRUE;
  512.             case IDCANCEL:
  513.             free_sounds();
  514.             EndDialog(hDlg, FALSE);
  515.             return TRUE;
  516.         }
  517.         break;
  518.     }
  519.     return FALSE;
  520. }
  521.  
  522. /* Get page number from dialog box and store in ppage */
  523. BOOL
  524. get_page(int *ppage, BOOL multiple)
  525. {
  526. DLGPROC lpProcPage;
  527. BOOL flag;
  528.     if (doc == (struct document *)NULL)
  529.         return FALSE;
  530.     if (doc->numpages == 0) {
  531.         gserror(IDS_NOPAGE, NULL, MB_ICONEXCLAMATION, SOUND_NONUMBER);
  532.         return FALSE;
  533.     }
  534.     page_list.current = *ppage - 1;
  535.     page_list.multiple = multiple;
  536.     if (page_list.select == (BOOL *)NULL)
  537.         return FALSE;
  538.     memset(page_list.select, 0, doc->numpages * sizeof(BOOL) );
  539.     lpProcPage = (DLGPROC)MakeProcInstance((FARPROC)PageDlgProc, phInstance);
  540.     flag = DialogBoxParam( phInstance, "PageDlgBox", hwndimg, lpProcPage, (LPARAM)NULL);
  541.     FreeProcInstance((FARPROC)lpProcPage);
  542.     if (flag && (page_list.current >= 0))
  543.         *ppage = page_list.current + 1;
  544.     return flag;
  545. }
  546.  
  547. BOOL CALLBACK _export
  548. PageDlgProc(HWND hDlg, UINT wmsg, WPARAM wParam, LPARAM lParam)
  549. {
  550.     char buf[40];
  551.     int i;
  552.     WORD notify_message;
  553.     switch (wmsg) {
  554.         case WM_INITDIALOG:
  555.         if (page_list.multiple)
  556.             LoadString(phInstance, IDS_SELECTPAGES, buf, sizeof(buf));
  557.         else
  558.             LoadString(phInstance, IDS_SELECTPAGE, buf, sizeof(buf));
  559.         SetWindowText(hDlg, buf);
  560.         for (i=0; i<doc->numpages; i++) {
  561.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_ADDSTRING, 0, 
  562.             (LPARAM)((LPSTR)doc->pages[map_page(i)].label));
  563.         }
  564.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, TRUE, MAKELPARAM(page_list.current,0));
  565.         SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETCURSEL, page_list.current, 0L);
  566.         if (!page_list.multiple) {
  567.             EnableWindow(GetDlgItem(hDlg, PAGE_ALL), FALSE);
  568.             EnableWindow(GetDlgItem(hDlg, PAGE_ODD), FALSE);
  569.             EnableWindow(GetDlgItem(hDlg, PAGE_EVEN), FALSE);
  570.         }
  571.         return TRUE;
  572.         case WM_COMMAND:
  573.         notify_message = GetNotification(wParam,lParam);
  574.         switch (LOWORD(wParam)) {
  575.             case PAGE_LIST:
  576.             if (notify_message == LBN_DBLCLK)
  577.                 PostMessage(hDlg, WM_COMMAND, IDOK, 0L);
  578.             return FALSE;
  579.             case PAGE_ALL:
  580.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SELITEMRANGE, TRUE, 
  581.                 MAKELPARAM(0,doc->numpages-1));
  582.             return FALSE;
  583.             case PAGE_ODD:
  584.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L)-1; i>=0; i--)
  585.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, !(i&1), MAKELPARAM(i,0));
  586.             return FALSE;
  587.             case PAGE_EVEN:
  588.             for (i=(int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCOUNT, 0, 0L); i>=0; i--)
  589.                 SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETSEL, (i&1), MAKELPARAM(i,0));
  590.             SendDlgItemMessage(hDlg, PAGE_LIST, LB_SETTOPINDEX, 0, 0L);
  591.             return FALSE;
  592.             case IDOK:
  593.             i = (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETCURSEL, 0, 0L);
  594.             page_list.current = (i == LB_ERR) ? -1 : i;
  595.             for (i=0; i<doc->numpages; i++) {
  596.               page_list.select[i] =
  597.                 (int)SendDlgItemMessage(hDlg, PAGE_LIST, LB_GETSEL, i, 0L);
  598.             }
  599.             EndDialog(hDlg, TRUE);
  600.             return TRUE;
  601.             case IDCANCEL:
  602.             EndDialog(hDlg, FALSE);
  603.             return TRUE;
  604.         }
  605.         break;
  606.     }
  607.     return FALSE;
  608. }
  609.  
  610.  
  611.  
  612. /* get user defined size */
  613. BOOL
  614. gsview_usersize()
  615. {
  616. char prompt[MAXSTR];
  617. char answer[MAXSTR];
  618.     LoadString(phInstance, IDS_TOPICMEDIA, szHelpTopic, sizeof(szHelpTopic));
  619.     LoadString(phInstance, IDS_USERWIDTH, prompt, sizeof(prompt));
  620.     sprintf(answer,"%d", user_width);
  621.     if (!get_string(prompt,answer) || atoi(answer)==0)
  622.         return FALSE;
  623.     user_width = atoi(answer);
  624.     LoadString(phInstance, IDS_USERHEIGHT, prompt, sizeof(prompt));
  625.     sprintf(answer,"%d", user_height);
  626.     if (!get_string(prompt,answer) || atoi(answer)==0)
  627.         return FALSE;
  628.     user_height = atoi(answer);
  629.     return TRUE;
  630. }
  631.  
  632.